﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using System.Data.SqlClient;
/// <summary>
/// Summary description for _Company
/// </summary>
public class _Company
{
	public _Company()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    public int _id { get; set; }
    public string _company_name { get; set; }
    public string _company_reg_nr{ get; set; }
    public string _company_vat { get; set; }
    public string _status { get; set; }

    static SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString);

    //Atlasam datus priekš MyCompanies.aspx saraksta iekš User_company.cs
    public static _Company SelectCompany(string id, string status)
    {
        _Company company = new _Company();
        SqlCommand sCmd = new SqlCommand("SELECT * FROM company WHERE id = @company_id AND (ISNULL(@status, '') = '' OR ISNULL(@status, '') = statuss)", conn);
        sCmd.Parameters.Add(new SqlParameter("@company_id", System.Data.SqlDbType.Int)).Value = id;
        sCmd.Parameters.Add(new SqlParameter("@status", System.Data.SqlDbType.NVarChar)).Value = status;
        conn.Open();
        SqlDataReader dr = sCmd.ExecuteReader();
        while (dr.Read())
        {
            company._id = (int) dr[0];
            company._company_name = dr[1].ToString();
            company._company_reg_nr = dr[2].ToString();
            company._company_vat = dr[3].ToString();
            company._status = dr[4].ToString();
        }
        dr.Close();
        conn.Close();
        return company;
    }

    //public static _Company SelectCompanyBY(string id, string status)
    //{
    //    _Company company_by = new _Company();
    //    SqlCommand sCmd = new SqlCommand("SELECT * FROM COMPANY WHERE id = @company_id AND status=@status", conn);
    //    sCmd.Parameters.Add(new SqlParameter("@company_id", System.Data.SqlDbType.Int)).Value = id;
    //    sCmd.Parameters.Add(new SqlParameter("@status", System.Data.SqlDbType.Int)).Value = status;
    //    conn.Open();
    //    SqlDataReader dr = sCmd.ExecuteReader();
    //    while (dr.Read())
    //    {
    //        company_by._id = (int) dr[0];
    //        company_by._company_name = dr[1].ToString();
    //        company_by._company_reg_nr = dr[2].ToString();
    //        company_by._company_vat = dr[3].ToString();
    //        company_by._status = dr[4].ToString();
    //    }
    //    dr.Close();
    //    conn.Close();
    //    return company_by;
    //}

    //public static _Company SelectClientTO(string id)
    //{
    //    _Company client_to = new _Company();
    //    SqlCommand sCmd = new SqlCommand("SELECT * FROM COMPANY WHERE id = @id AND status=@status", conn);
    //    sCmd.Parameters.Add(new SqlParameter("@id", System.Data.SqlDbType.Int)).Value = id;
    //    sCmd.Parameters.Add(new SqlParameter("@status", System.Data.SqlDbType.Int)).Value = status;
    //    conn.Open();
    //    SqlDataReader dr = sCmd.ExecuteReader();
    //    while (dr.Read())
    //    {
    //        client_to._id = (int) dr[0];
    //        client_to._company_name = dr[1].ToString();
    //        client_to._company_reg_nr = dr[2].ToString();
    //        client_to._company_vat = dr[3].ToString();
    //        client_to._status = dr[4].ToString();
    //    }
    //    dr.Close();
    //    conn.Close();
    //    return client_to;
    //}
}